package Helper;

import java.awt.Button;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import GUI.GameScreen;
import GameObjects.Physics.Position;

public abstract class HelperMethods 
{
	public static double vectorAngle(double dx, double dy) 
	{
		double adx = Math.abs(dx);
		double ady = Math.abs(dy);
		if (dx >= 0) 
		{
			if (dy > 0) {
				return -Math.atan(ady / adx);
			} else {
				return Math.atan(ady / adx);
			}
		} 
		else 
		{
			if (dy <= 0) {
				return Math.PI - Math.atan(ady / adx);
			} else {
				return -(Math.PI - Math.atan(ady / adx));
			}
		}
	}
	
	public static Button makeButton(JPanel panel, String name, ActionListener actionListener)
	{
		Button button = new Button(name);
		button.addActionListener(actionListener);
		panel.add(button);
		return button;
	}
	
	public static double degreesToRadians(double theta)
	{
		return theta * Math.PI/180;
	}
	
	public static boolean outOfBounds(Position position)
	{
		return position.x() < 0 || position.x() > GameScreen.WIDTH || position.y() < 0 || position.y() > GameScreen.HEIGHT;
	}
	
	public static double round2(double number) 
	{
		double result = number * 100;
		result = Math.round(result);
		result = result / 100;
		return result;
	}
}
